package flc.ast.utils;

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

import flc.ast.bean.PicAlbumBean;

public class SortUtils {

    public static void getSortShotBefore(List<PicAlbumBean> picAlbumBeanList) {
        Collections.sort(picAlbumBeanList, new Comparator<PicAlbumBean>() {
            @Override
            public int compare(PicAlbumBean lhs, PicAlbumBean rhs) {
                Date date1 = stringToDate(lhs.getTime());
                Date date2 = stringToDate(rhs.getTime());
                // 对日期字段进行升序，如果欲降序可采用after方法
                if (date1.before(date2)) {
                    return 1;
                }
                return -1;
            }
        });
    }

    private static Date stringToDate(String dateString) {
        ParsePosition position = new ParsePosition(0);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd（EEEE）");
        return simpleDateFormat.parse(dateString, position);
    }
}
